package top.healthylife.gateway.platform.youshu.api.api;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.healthylife.gateway.core.service.ParentFace;
import top.healthylife.gateway.dto.annotation.ApiServiceExplain;
import top.healthylife.gateway.platform.youshu.api.utils.YoushuHttpUtil;
import top.healthylife.gateway.platform.youshu.dto.apia501.req.YoushuReqEnterpriseRelationInfoDto;
import top.healthylife.gateway.platform.youshu.dto.apia501.res.YoushuResEnterpriseRelationInfoDto;

/**
 * @author : GaoZeXi
 * @date 2021/8/8 14:16
 */
@Slf4j
@Service
@ApiServiceExplain(price = 20, apiName = "企业关联人查询", info = "接口Id:A501")
public class YoushuEnterpriseRelationInfoApi implements ParentFace<YoushuReqEnterpriseRelationInfoDto, YoushuResEnterpriseRelationInfoDto> {

    static final String API_CODE = "A501";

    @Override
    public YoushuResEnterpriseRelationInfoDto execute(YoushuReqEnterpriseRelationInfoDto t) throws Exception {
        String cid = t.getCid();
        if (ObjectUtil.isNotEmpty(cid)) {
            //MD5 加密，唯一标识（cid）加密前最后一位 X 大写，加密后 的数据需要小写。
            cid = cid.substring(0, cid.length() - 1) + cid.substring(cid.length() - 1).toUpperCase();
            String encrypt = SecureUtil.md5(cid);
            t.setCid(encrypt);
        }

        return YoushuHttpUtil.httpRequest(t, API_CODE, YoushuResEnterpriseRelationInfoDto.class);
    }
}
